package vsvm.data.model;

import vsvm.graphics.charts.HistogramChart;
import vsvm.gui.Environment;
import vsvm.gui.IActionsProvider;
import vsvm.gui.IQuickInfoProvider;
import vsvm.gui.VSVMInternalFrame;
import vsvm.gui.forms.SummaryDialog;
import vsvm.math.statistics.Characteristics;
import vsvm.math.statistics.histogram.Histogram;

public abstract class AbstractAttribute implements java.io.Serializable, IActionsProvider, Cloneable, IQuickInfoProvider {
	static String AC_INFO = "Attribute info";
	static String AC_HISTOGRAM = "Histogram";
	
	protected String name;
	protected AbstractDataModel parent;
	public static final int NUMERIC_TYPE 	= 1;
	public static final int CATEGORIAL_TYPE = 2;
	 
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void setParent(AbstractDataModel model) {
		parent = model;
	}

	public AbstractDataModel getParent() {
		return parent;
	}	
	
	public abstract int getAttributeType();		// enumas?
	
	public abstract double toDouble(String str);
	
	public String toString() {
		return name;
	}

	public void executeAction(String action) {
		if (action.equals(AC_INFO)) {
			double[] d = parent.getAttributeData(this);
			Object[][] data = new Object[8][];
			for (int i = 0; i < 8; ++i) data[i] = new Object[2];
			data[0][0] = "Number of values";
			data[0][1] = d.length;
			data[1][0] = "Minimum value";
			data[1][1] = Characteristics.getMin(d);
			data[2][0] = "Maximum value";
			data[2][1] = Characteristics.getMax(d);
			data[3][0] = "Mean";
			data[3][1] = Characteristics.getMean(d);
			data[4][0] = "Standard deviation";
			data[4][1] = Characteristics.getStDev(d);
			data[5][0] = "Variance";
			data[5][1] = Characteristics.getVariance(d);
			data[6][0] = "Kurtosis";
			data[6][1] = Characteristics.getKurtosis(d);;
			data[7][0] = "Skewiness";
			data[7][1] = Characteristics.getSkewness(d);
			
			SummaryDialog sd = new SummaryDialog("Attribute " + name + " info", data);
			Environment.getEnvironment().getMainFrame().addWindow(sd);
			sd.setVisible(true);
		} else if (action.equals(AC_HISTOGRAM)) {
			Histogram h = new Histogram(parent, this);
			HistogramChart ch = new HistogramChart(this.getName() + " attribute histogram", h);
			VSVMInternalFrame ifr = new VSVMInternalFrame("" + (this.parent.getAtttributeIndex(this) + 1));		
			
			ifr.add(ch);			
					
			Environment.getEnvironment().getMainFrame().addWindow(ifr);
			ifr.setVisible(true);
			
		}
		
	}

	public String[] getActions() {
		return new String[] {AC_INFO, AC_HISTOGRAM };
	}
	
	

	
	
}
